<!-- 入库订单 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />


    <ex_super_table_page v-bind="option" ref="SuperTablePage" 
      @selection-change="e => selection = e">
    </ex_super_table_page>



  </div>
</template>
<script>
import business_function from "@/common/business_function"

import moment from 'moment-mini-ts'
import superTablePageFunction from '@/mixin/super-table-page-function';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'order>>outbound_manage'
import page_table_model_manage from '@/mixin/page_table_model_manage';
export default {

  title: "title_intercept_order_list",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: {},


  data() {
    return {


      selection: [],

      limitDate: null,
      option: {
        search: {
          formDataHandle: (data) => {
            const out = _.cloneDeep(data)
            if (out.daterange.length >= 2) {
              out.startInterceptTime = out.daterange[0]
              out.endInterceptTime = out.daterange[1]
            }
            return out
          },
          default: {
            interceptFlag: "Y",
            daterange: [moment().set({ 'hours': 0, 'minutes': 0, 'seconds': 0, 'milliseconds': 0 }).subtract(3, 'months').valueOf(), moment().set({ 'hours': 23, 'minutes': 59, 'seconds': 59, 'milliseconds': 0 }).valueOf()]
          },
          model: [
            { label: "label_intercept_status", key: "interceptStatus", type: 'select', enum: 'OrderInterceptStatusEnum', },
            {
              label: "label_order_code", key: "outOrderNos", attrs: {
                placeholder: 'tip_input_can_comma_separated'
              }
            },
            { label: "label_platform_code", key: "platformOrderNo", },
            { label: "label_outbound_type", key: "outType", type: 'select', enum: 'OmsOutboundOrderTypeEnum', },


            { label: "label_customer", key: "customerIds", type: 'common_customer_choose', multiple: true, },

            {
              label: "label_intercept_order_time", key: "daterange", type: 'date-picker', fold: false,
              attrs: {
                clearable: false,
                type: 'datetimerange', 'default-time': ['00:00:00', '23:59:59'],
                'popper-class': "no_clear_range_picker",
                'picker-options': {
                  shortcuts: this.$date_range_shortcuts(),
                  onPick: (d) => {
                    this.limitDate = d.minDate
                  },
                  disabledDate: (t) => {
                    if (moment(t).isAfter(moment().set({ 'hours': 23, 'minutes': 59, 'seconds': 59, 'milliseconds': 999 }))) return true
                    if (this.limitDate != null) {
                      if (moment(t).isAfter(moment(this.limitDate).add(3, 'months')) ||
                        moment(t).isBefore(moment(this.limitDate).subtract(3, 'months'))) {
                        return true
                      }
                    }
                    return false
                  }
                },
              },
              on: {
                blur: () => { this.limitDate = null }
              }
            },
            { label: "label_is_second_put", key: "twicePutawayFlag", type: 'select', enum: 'YesOrNoEnum', },



            { label: "label_consignee_person_name", key: "consignee", fold: true, },
            { label: "label_sku", key: "skuId", type: 'sku_selec_input', fold: true, },

          ],
        },
        actionExtra: [
        { label: 'label_export',attrs: { type: "primary" }, click: this.exportExcel },

        ],
        table: {
          url: "/oms-api/client/OutboundOrderClientRpc/selectListPage.json",
          urlParams: (params) => {
            return params

          },
          model: this.init_table_model(),
        },
      },

   
  
    };
  },



  methods: {

    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },
        {
          key: 'orderNo', label: 'label_order_code', 'width': 170,
        },
        { key: 'ecPlatformOrderNo', label: 'label_ec_platform_code', 'width': 170, },
        { key: 'customerName', label: 'label_customer_name', 'width': 100, 'show-overflow-tooltip': true, },
        { key: 'customerCode', label: 'label_customer_code', 'width': 100, 'show-overflow-tooltip': true, },

        {  key: "interceptStatus",label: "label_intercept_status", 'width': 120, 'show-overflow-tooltip': true,formatter: (r, c, v) => this.$enumShow(v, "OrderInterceptStatusEnum"), },
        {  key: "interceptCause",label: "label_intercept_reason", 'width': 120, 'show-overflow-tooltip': true, },
        {  key: "interceptTime",label: "label_intercept_order_time", 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        {  key: "twicePutawayFlag",label: "label_is_second_put", 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "YesOrNoEnum") },

        { key: 'bizType', label: 'label_business_type', 'width': 100, formatter: (r, c, v) => this.$enumShow(v, "BizTypeEnum") },

        { key: 'outType', label: 'label_outbound_type', 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "OmsOutboundOrderTypeEnum") },
        
        { key: 'outStatus', label: 'label_order_status', 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "OmsOutboundOrderStatusEnum") },
        
        { key: 'ecPlatform', label: 'label_ec_platform', 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "OmsOutboundOrderEcPlatformEnum") },
        { key: 'warehouseCode', label: 'label_outbound_warehouse', 'width': 140, 'show-overflow-tooltip': true, },
        { key: 'logisticsName', label: 'label_logistics', 'width': 140, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$formatNameCode(v, r.logisticsCode) },
        { key: 'trackNumber', label: 'label_track_code', 'width': 140, 'show-overflow-tooltip': true, },
      
        { key: 'gmtCreate', label: 'label_create_order_date', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'outDate', label: 'label_outbound_date', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        {
          type: 'operate', width: 170, fixed: 'right', operate: [
            {
              type: 'more',
              items: [
                { label: 'label_view_detail', click: (row) => this.clickDetail(row) },
              ]
            }
          ],
        }
      ]
    },
   

    isSelectable(row) {
      return ['DRAFT', 'GET_TRACK_NUMBER'].some(e => e == row.outStatus)
    },

    clickDetail(row) {

      this.$router.push({
        path: '/page/oms/order/outbound/order_detail', query: { id: row.id, }
      })
    },


    exportExcel() {
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchFormData(),
        model: this.option.search.model,
        selection: this.selection,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              idList: selection.map(it => it.id)
            }
          } else {
            params = data
          }
          this.$functionCommon({
            url: "/oms-api/client/OutboundOrderClientRpc/exportInterceptOrderExcel.json",
            data: params,
          })
        }
      })
    },
  }
};

</script>
<style>

</style>
